function testRegCard(card)
{	
	var regDataForm = document.forms["form_RegistrationData"];
top.RegDataCorr = true	
	if (card == 1)
	{
	if (regDataForm.elements["reg_Name"].value == "")
	{
		top.RegDataCorr = false;
		focus_('reg_Name', 1);
		return;
	}	

	if (regDataForm.elements["reg_Address"].value == "")
	{
		top.RegDataCorr = false;
		focus_('reg_Address', 1);
		return;
	}	

	if (regDataForm.elements["reg_PostalCode"].value == "")
	{
		top.RegDataCorr = false;
		focus_('reg_PostalCode', 1);
		return;
	}	

	if (regDataForm.elements["reg_City"].value == "")
	{
		top.RegDataCorr = false;
		focus_('reg_City', 1);
		return;
	}	

	if (regDataForm.elements["reg_Country"].value == "")
	{
		top.RegDataCorr = false;
		focus_('reg_Country', 1);
		return;
	}	

	if (regDataForm.elements["reg_PhoneNo"].value == "")
	{	top.RegDataCorr = false;
		focus_('reg_PhoneNo', 1);
		return;
	}	

	if (!top.testEmail(regDataForm.elements["reg_Email"].value))
	{
		top.RegDataCorr = false;
		focus_('reg_Email', 1);
		return;
	}
	}
	else if (card == 2)
	{
	if (testDate(regDataForm.elements["reg_DateOfPurchase"].value) == 0)
	{	top.RegDataCorr = false;
		focus_('reg_DateOfPurchase', 2);
		return;
	}	
	if (regDataForm.elements["reg_SerialNo"].value == "")
	{	top.RegDataCorr = false;
		focus_('reg_SerialNo', 2);
		return;
	}	
	if (regDataForm.elements["reg_StoreName"].value == "")
	{	top.RegDataCorr = false;
		focus_('reg_StoreName', 2);
		return;
	}	
	if (regDataForm.elements["reg_StoreCity"].value == "")
	{	top.RegDataCorr = false;
		focus_('reg_StoreCity', 2);
		return;
	}	

	};

}




function testDate(date)
{
	if (date == "")
	{
		return 0;
	};

	if (ValiDate(date, "dd-mm-yyyy"))
		{
		return 1;
		};	
	return 0;
}

function write_defaults()
{
	var regDataForm = document.forms["form_RegistrationData"];
	now = new Date();
	day = ((now.getDate() < 10) ? "0" : "") + now.getDate();
	mon = (((1+now.getMonth()) < 10) ? "0" : "") + (now.getMonth()+1);
	year = now.getYear();
	strdate = day + "-" + mon + "-" + year;
	regDataForm.reg_DateOfRegistration.value = strdate;
}


function ThrowRegData(szRegStr)
{
	return "";
}

function ShowRegData()
{
	var regDataForm = document.forms["form_RegistrationData"];
	regDataForm.elements["reg_Product"].value = top.sessVars["product_name"];
	regDataForm.elements["reg_ArticleCode"].value = top.sessVars["device_selected"];
	regDataForm.elements["reg_Platform"].value = top.OSVersion[top.sessVars["CurrentOS"]];
	regDataForm.elements["reg_Name"].value = top.ThrowRegData("Name");
	regDataForm.elements["reg_Address"].value = top.ThrowRegData("Address");
	regDataForm.elements["reg_PostalCode"].value = top.ThrowRegData("PostalCode");
	regDataForm.elements["reg_City"].value = top.ThrowRegData("City");

//	regDataForm.elements["reg_Company"].value = top.ThrowRegData("Company");

	regDataForm.elements["reg_Country"].value = top.ThrowRegData("Country");
	regDataForm.elements["reg_PhoneNo"].value = top.ThrowRegData("PhoneNo");
	regDataForm.elements["reg_Email"].value = top.ThrowRegData("Email");

	regDataForm.elements["reg_SerialNo"].value = top.ThrowRegData("SerialNo");
	regDataForm.elements["reg_DateOfPurchase"].value = top.ThrowRegData("DateOfPurchase");
	regDataForm.elements["reg_StoreName"].value = top.ThrowRegData("StoreName");
	regDataForm.elements["reg_StoreCity"].value = top.ThrowRegData("StoreCity");
	regDataForm.elements["reg_DateOfRegistration"].value = top.ThrowRegData("DateOfRegistration");	

	if ( top.ThrowRegData("ReceiveUpdates") == 1)
	{
		regDataForm.elements["reg_ReceiveUpdates"].checked = true;
	}
	else
	{
		regDataForm.elements["reg_ReceiveUpdates"].checked = false;
	}
	if ( top.ThrowRegData("ReceiveNews") == 1)
	{
		regDataForm.elements["reg_ReceiveNews"].checked = true;
	}
	else
	{
		regDataForm.elements["reg_ReceiveNews"].checked = false;
	}

}

// ::
function testRegInfo( regObj )
{
	top.sessVars["regData_changed"] = true;
}

// ::
function RegisterProp (propName, propOrder, propType, propValue, validateProc)
{
	if (propType == 0)
	{
		if (propValue != "")
		{
			top.RegisterDeviceProp(propName, propValue);
			top.aCardComplete[propOrder] = 1;
		}
		else
		{
			top.aCardComplete[0] = 0;
			top.aCardComplete[propOrder] = 0;
		}
	}
	if (propType == 1)
	{
		top.aCardComplete[propOrder] = 1;
		if (propValue)
		{
			top.RegisterDeviceProp(propName, 1);
		}
		else
		{
			top.RegisterDeviceProp(propName, 0);
		}
	}
}

// ::
function RegisterDevice()
{
	var regDataForm = document.forms["form_RegistrationData"];
	
	RegisterProp("Name", 1, 0, regDataForm.elements["reg_Name"].value, "");

	regValue = regDataForm.elements["reg_Email"].value;
	
	if (top.testEmail(regValue))
	{
		top.RegisterDeviceProp("Email", regValue);
		top.aCardComplete[3] = 1;
	}
	else
	{
		top.aCardComplete[0] = 0;
		top.aCardComplete[3] = 0;
	}
	
	RegisterProp("Company", 2, 0, "not available", "");
	RegisterProp("ConnectionType", 4, 0, "not available", "");

	RegisterProp("ReceiveNews", 16, 1, regDataForm.elements["reg_ReceiveNews"].checked, "");
	RegisterProp("ReceiveUpdates", 17, 1, regDataForm.elements["reg_ReceiveUpdates"].checked, "");

	RegisterProp("Address", 5, 0, regDataForm.elements["reg_Address"].value, "");
	RegisterProp("PostalCode", 7, 0, regDataForm.elements["reg_PostalCode"].value, "");
	RegisterProp("City", 8, 0, regDataForm.elements["reg_City"].value, "");
	RegisterProp("Country", 9, 0, regDataForm.elements["reg_Country"].value, "");
	RegisterProp("PhoneNo", 10, 0, regDataForm.elements["reg_PhoneNo"].value, "");

	RegisterProp("SerialNo", 11, 0, regDataForm.elements["reg_SerialNo"].value, "");

	regValue = regDataForm.elements["reg_DateOfPurchase"].value;
	if (testDate(regValue))
	{
		RegisterProp("DateOfPurchase", 12, 0, regValue, "");
	}
	else
	{
		top.aCardComplete[0] = 0;
		top.aCardComplete[12] = 0;
	}

	RegisterProp("StoreName", 13, 0, regDataForm.elements["reg_StoreName"].value, "");
	RegisterProp("StoreCity", 14, 0, regDataForm.elements["reg_StoreCity"].value, "");

	regValue = regDataForm.elements["reg_DateOfRegistration"].value;
	if (testDate(regValue))
		{
		RegisterProp("DateOfRegistration", 15, 0, regValue, "");
		}
	else
		{
		top.aCardComplete[0] = 0;
		top.aCardComplete[15] = 0;
		}

	top.RegisterDeviceProp("Product", "");
	top.RegisterDeviceProp("Article", "");
	top.RegisterDeviceProp("Platform", "");			
}

// ::
function createBenefitsWindow()
{
	if (top.sessVars["passedBenefitsWindow"] == false) { top.JumpToBenefitsPage() }
}

// ::
function showBenefitsWindow()
{
	if ((top.sessVars["passedBenefitsWindow"] == false) && (top.sessVars["preTask"] != "register"))
	{
		top.sessVars["shownBenefitsWindow"] = true;
		top.sessVars["task"] = 911;
		Err = top.HideSelects();
		document.all["benefitsdiv"].style.visibility = "visible";
	}
	else
	{
		top.ShowSelects();
		focus_('reg_Name', 1);
	}
}

// ::
function clickedBenefitsOK()
{
	top.sessVars["task"] = 0;
//	document.all["benefitsdiv"].style.visibility = "hidden";
	top.sessVars["passedBenefitsWindow"] = true;
	top.ShowSelects();
	
	/*
	if (typeof document.all["reg_ConnectionType"] != "undefined")
	{
		document.all["reg_ConnectionType"].style.visibility = "visible";
	}
	*/
	
	focus_('reg_Name', 1);
}

//::
function createAlertDivs()
{
	createAppDiv();
	createProgressBar();
	createAlertDiv();
	createAlert2Div();
	createBenefitsWindow();
	clickedBenefitsOK();
}


// :: [+] Sitecom 040720
function isTel (string) 
{
  var addressPattern = 
	/^\d+[-\ ]?\d+$/;
  return addressPattern.test(string);
}

// :: [+] Sitecom 040720
function ValiDate(date, format)
{
   dateBits = DateComponents(date, format);
   
   if (dateBits == null) return false;

   day = dateBits[0];
   month = dateBits[1];
   year = dateBits[2];

   if (  (year < 999) || (year > 3000 ))
	{
		return false;
	}		

   if ((month < 1 || month > 12) || (day < 1 || day > 31)) { // check month range 
        return false;
   } 
   
   if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        return false;
   }
	      
   if (month == 2) {
	testyear = year;
       // check for february 29th 
       if(year < 20){
       	testyear = 20 + year;
   }else if(year<100){
      	testyear = 19 + year;
   }	       
   var isleap = (testyear % 4 == 0 && (testyear % 100 != 0 || testyear % 400 == 0)); 
       if (day>29 || (day==29 && !isleap)) {
           return false;
          }
       } 
  	   
   return true;
}

// :: [+] Sitecom 040720
function DateComponents(dateStr, morfat) {
  var splitChar = (morfat.indexOf('-')>0?'-':(morfat.indexOf('/')>0?'/':(morfat.indexOf('.')>0?'.':'')));
  var morfatArr = morfat.split(splitChar);
  var dateArr = dateStr.split(splitChar);
  var retArr = new Array(morfatArr.length);  
    
  if(dateArr.length == morfatArr.length){
	  for(i=0;i<morfatArr.length;i++){
		if(morfatArr[i]=="dd" && dateArr[i]<=31){			
			retArr[0] = dateArr[i];
		}else if(morfatArr[i]=="mm" && dateArr[i]<=12){
			retArr[1] = dateArr[i];
		}else if(morfatArr[i]=="yyyy" && dateArr[i]<3000 && dateArr[i]>999){
			retArr[2] = dateArr[i];
		}else if(morfatArr[i]=="yy" && dateArr[i]<100 && dateArr[i]>=0){
			retArr[2] = dateArr[i];
		}else{
			return null;
		}
	  }	  
	  return retArr;
  }else{
    return null;
  }
}

